﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Contact.API.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Contact.API.Controllers
{
    [Produces("application/json")]
    [Route("api/Base")]
    public class BaseController : Controller
    {
        protected UserIdentity UserIdentity
        {
            get
            {
                var identity = new UserIdentity();
                var claims = User.Claims;
                int.TryParse(claims.FirstOrDefault(c=>c.Type=="id").Value, out int userId);
                identity.UserId = userId;
                identity.Name = claims.FirstOrDefault(c => c.Type == "name").Value;
                identity.Title = claims.FirstOrDefault(c => c.Type == "title").Value;
                identity.Company = claims.FirstOrDefault(c => c.Type == "company").Value;
                identity.Avatar = claims.FirstOrDefault(c => c.Type == "avatar").Value;
                return identity;
            }
        }
    }
}